<!doctype html>
<html style="height:100%">
<head>
<meta charset="utf-8">
<title>新建图文消息</title>
<link rel="stylesheet" type="text/css" href="<{$ipath}>wx/style/addnews.css" media="all" />
<link rel="stylesheet" type="text/css" href="<{$ipath}>index/style/float-manage.css" media="all" />
<link href="<{$ipath}>index/style/fuceng.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript"  src="<{$ipath}>public/js/head.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/jquery.min.js"></script>
<script type="text/javascript"  src="<{$ipath}>wx/js/ajaxfileupload.js"></script>
<script charset="utf-8" src="lib/kdeditor/kindeditor.js"></script>
<script charset="utf-8" src="lib/kdeditor/lang/zh_CN.js"></script>
<script>
var K=window.KindEditor;
function uploadpic(n){
	$('.loading').css({'display':'-webkit-box;'});
	var url='?g=wx&m=weixin&a=upnewspic&imgname=img'+n;
	$.ajaxFileUpload({
			url:url,
			dataType:'json',
			fileElementId:"img"+n,
			type:'post',
			secureuri:false,
			success:function(data){
				$('.loading').hide();
				if(data.error==1000 || data.error=='1000'){
					var pic = data.pic;
					$("#nav").find(".navid_"+n+" span").html('<input type="hidden" name="media_id'+n+'" value="'+data.media_id+'" />');
					$("#nav").find(".navid_"+n).find("img").attr("src",pic);
				}else{
					alert(data.msg);
					return false;
				}
			},
		});
}

$(function(){
	//alert(1);
	var secs = $('.sec-sort-container');
	//alert(secs.length);
	$('.first-sort li').each(function(index, el) {
		$(this).click(function(event) {
			$(this).addClass('cur').siblings('li').removeClass('cur');
			$(this).css({
				background: ' url(http://test.s.zhongsou.com/index/images/g-arrow.png) no-repeat 90% center'
				/*borderRight: 'none'*/
			}).siblings().css({
				background: ' url(http://test.s.zhongsou.com/index/images/w-arrow.png) no-repeat 90% center'
				/*borderRight: '1px solid #ddd'*/
			});
			secs.eq(index).show().siblings().hide();
		});
	});
	$('.sec-sort li').each(function(index, el) {
		$(this).click(function(event) {
			$(this).addClass('secCur').siblings().removeClass('secCur');
		});
	});
	$('header i').click(function(event) {
		$('#above').hide();
		$('#shade').hide();
	});
})
</script>
</head>
<body style="height:100%">
<div id="wxnews">
<form action="?g=wx&m=weixin&a=wxnews" method="post" target="hiddfrm">
	<h1><{if !empty($list)}>修改图文消息<{else}>新建图文消息<{/if}><input type="hidden" id="maxeditid" data-id="<{$maxeditid}>" value="<{$maxeditid}>"></h1>
    <div class="newsedit">
    	<ul id="nav">
       	  <h2>图文导航</h2>
          <{if !empty($list)}>
          	<dl data-id="1" class="first select navid_1">
          <div onclick="selnav(this)">
            	<dt><img width="100%" style="max-height:135px;" src="<{$list.0.url}>"><span class="pichiddvalue"><input type="hidden" value="<{$list.0.thumb_media_id}>" name="media_id1"></span></dt>
                <dd class="navtit"><{$list.0.title}></dd>
          </div>
            </dl>
            <div class="navaddcontent">
            <{section name=l loop=$list start=1}>
            	<dl data-id="<{$smarty.section.l.iteration + 1}>" class="normal navid_<{$smarty.section.l.iteration + 1}>">
                    <div onclick="selnav(this)">
                        <dd class="tit navtit"><{$list[l].title}></dd>
                        <dd class="img"><img width="100%" src="<{$list[l].url}>"><span class="pichiddvalue"><input type="hidden" value="<{$list[l].thumb_media_id}>" name="media_id<{$smarty.section.l.iteration + 1}>"></span></dd>
                    </div>
                    <dd style="display:block" onclick="delnav(<{$smarty.section.l.iteration + 1}>)" class="editmode"><i class="icon_del"></i></dd>
                </dl>
            <{/section}>
            </div>
          <{else}>
          <dl class="first navid_1" data-id="1">
          <div onClick="selnav(this)">
            	<dt><img src="<{$ipath}>wx/images/normalimg.png" width="100%" style="max-height:135px;" /><span class="pichiddvalue"></span></dt>
                <dd class="navtit">标题</dd>
          </div>
            </dl>
            <div class="navaddcontent"></div>
          <{/if}>
          <{if empty($list)}>
           <li id="addnews"><i class="icon_add" onClick="addedit()"></i></li>
           <{/if}>
        </ul>
    	<div id="edit">
        <{if !empty($list)}>
        <{section name=l loop=$list}>
            <div class="editid_<{$smarty.section.l.iteration}> editcontent" data-id="<{$smarty.section.l.iteration}>" <{if $smarty.section.l.iteration==1}>style="display:block"<{else}>style="display:none"<{/if}>>
                  <ul class="baseedit">
                  <li><input type="text" name="title<{$smarty.section.l.iteration}>" id="title<{$smarty.section.l.iteration}>" class="title" onBlur="settit(this)" value="<{$list[l].title}>" /></li>
                  <li><input type="text" name="author<{$smarty.section.l.iteration}>" id="author<{$smarty.section.l.iteration}>" class="author" placeholder="请输入作者" value="<{$list[l].author}>" /></li>
                  <li><textarea name="content<{$smarty.section.l.iteration}>" id="content<{$smarty.section.l.iteration}>" class="content" style="visibility:hidden;"><{$list[l].content}></textarea></li>
                  <li>图文链接:<input type="text" name="linkurl<{$smarty.section.l.iteration}>" class="linkurl<{$smarty.section.l.iteration}> wxtextput" value="<{$list[l].content_source_url}>" /> <input type="button" class="wxbutton" value="从功能库选择" onClick="showabove(<{$smarty.section.l.iteration}>)" /></li>
                  </ul>
                  <script>K.create("#content<{$smarty.section.l.iteration}>",{cssPath:"lib/kdeditor/plugins/code/prettify.css",uploadJson:"lib/kdeditor/php/upload_json.php",fileManagerJson:"lib/kdeditor/php/file_manager_json.php",allowFileManager:true,});</script>
                  <ul class="moreedit">
                    <li>发布样式编辑</li>
                    <li>封面 <span>小图片建议尺寸：200像素 * 200像素</span></li>
                    <li><input type="file" class="fhidden" name="img<{$smarty.section.l.iteration}>" id="img<{$smarty.section.l.iteration}>" onChange="uploadpic(<{$smarty.section.l.iteration}>)" /><input type="button" class="wxbutton_normal" value="本地上传" /> <input type="button" class="wxbutton_normal" onClick="getmedialist(<{$smarty.section.l.iteration}>)" value="选择素材" /></li>
                    <li>摘要 <span>选填，如果不填写会默认抓取正文前54个字</span></li>
                    <li><textarea name="desc<{$smarty.section.l.iteration}>" id="desc<{$smarty.section.l.iteration}>" class="desc"><{$list[l].digest}></textarea></li>
                  </ul>
             </div>
         <{/section}>
        <{else}>
         <div class="editid_1 editcontent" data-id="1">
              <ul class="baseedit">
              <li><input type="text" name="title1" id="title1" class="title" onBlur="settit(this)" placeholder="请在这里输入标题" /></li>
              <li><input type="text" name="author1" id="author1" class="author" placeholder="请输入作者" /></li>
              <li><textarea name="content1" id="content1" class="content" style="visibility:hidden;"></textarea></li>
              <li>图文链接:<input type="text" name="linkurl1" class="linkurl1 wxtextput" /> <input type="button" class="wxbutton" value="从功能库选择" onClick="showabove(1)" /></li>
              </ul>
              <script>K.create("#content1",{cssPath:"lib/kdeditor/plugins/code/prettify.css",uploadJson:"lib/kdeditor/php/upload_json.php",fileManagerJson:"lib/kdeditor/php/file_manager_json.php",allowFileManager:true,});</script>
              <ul class="moreedit">
                <li>发布样式编辑</li>
                <li>封面 <span>小图片建议尺寸：200像素 * 200像素</span></li>
                <li><input type="file" class="fhidden" name="img1" id="img1" onChange="uploadpic(1)" /><input type="button" class="wxbutton_normal" value="本地上传" /> <input type="button" class="wxbutton_normal" onClick="getmedialist(1)" value="选择素材" /></li>
                <li>摘要 <span>选填，如果不填写会默认抓取正文前54个字</span></li>
                <li><textarea name="desc1" id="desc1" class="desc"></textarea></li>
              </ul>
         </div>
         <{/if}>
  	  </div>
      <div class="saveedit"><{if !empty($view)}><input type="hidden" name="id" value="<{$view.id}>" /><{/if}><input type="submit" class="wxsubmit" value="保存" />
      </div>
      
    </div>
    </form>
</div>
<div id="shade"></div>
<div id="showmedialist" class="hidddiv">
	<h3>选择素材<em onClick="closeshowmedialist()"><i class="icon_close"></i></em></h3>
    <ul id="showimglist"></ul>
    <h4><input type="hidden" id="mediashowid" value="" /><input type="hidden" id="mediashowurl" value="" /><input type="button" class="wxbutton_cancel" id="mediashowsetbutton" value="确认"> <input type="button" class="wxbutton_cancel" onClick="closeshowmedialist()" value="取消" /></h4>
</div>
<div id="above" style="z-index:9999">
    <div class="layer">
        <header>
            <span class="title">标题</span>
            <span class="subTitle">副标题</span>
            <i></i>
        </header>
        <div class="first-sort-container">
            <ul class="first-sort fl">
                <li class="cur">微网站</li>
                <li>宣传展示类</li>
                <li>推广吸粉类</li>
                <li>营销活动类</li>
                <li>行业功能类</li>
            </ul>
        </div>
        <div class="whole-sec fl tab_box">
            <div class="sec-sort-container ">
                <ul class="sec-sort c16" >

                </ul>
            </div>
            <div class="sec-sort-container  disN">
                <ul class="sec-sort c5">

                </ul>
            </div>
            <div class="sec-sort-container  disN">
                <ul class="sec-sort c6 ">

                </ul>
            </div>
            <div class="sec-sort-container  disN">
                <ul class="sec-sort c7">

                </ul>
            </div>
            <div class="sec-sort-container  disN">
                <ul class="sec-sort c9">

                </ul>
            </div>
        </div>
        <div class="sort-content fl">
            <ul class="addd">

            </ul>

        </div>
    </div>
    </div>
    <div class="loading"><img src="<{$ipath}>wx/images/loading.gif" /></div>
<script>
function getmedialist(n){
	var str='';
	url='?g=wx&m=weixin&a=getmedialist&type=img';
	$.get(url,function(data){
		if(data=='' || data==null){
			str+='<li class="showmedia_nono">暂时没有素材</li>';
		}else{
			for(ritem in data){
				str+='<li class="showmedia_img" onclick="setmediashowid(\''+data[ritem].media_id+'\',\''+data[ritem].url+'\','+n+',this)"><img src="'+data[ritem].url+'" width="120" height="120" /></li>';
			}
		$("#showimglist").append(str);
		$("#shade").show();
		$("#showmedialist").show();
		$("#showimglist").show();
		}
	},'json');
}
function setmediashowid(mid,url,n,obj){
	$("#mediashowid").val(mid);
	$("#mediashowurl").val(url);
	$("#mediashowsetbutton").attr("class","wxbutton");
	$("#mediashowsetbutton").attr("onclick","setmedia("+n+")");
	$(obj).parent().find(".icon_issel").remove();
	$(obj).append('<i class="icon_issel"></i>');
	
}
function setmedia(n){
	var media_id=$("#mediashowid").val();
	var url=$("#mediashowurl").val();
	$("#nav").find(".navid_"+n).find("img").attr("src",url);
	$("#nav").find(".navid_"+n+" .pichiddvalue").html('<input type="hidden" name="media_id'+n+'" value="'+media_id+'" />');
	closeshowmedialist();
}
function closeshowmedialist(){
	$("#shade").hide();
	$("#showmedialist").hide();
	$("#mediashowsetbutton").attr("onclick",'');
	$("#mediashowsetbutton").attr("class","wxbutton_cancel");
	$("#showmedialist").children("ul").html('');
	$("#showmedialist").children("ul").hide();
}
function settit(obj){
	var id = $(obj).parent().parent().parent().attr("data-id");
	$("#nav").find(".navid_"+id).find(".navtit").html($(obj).val());
}
function closehidd(){
	$(".hidddiv").hide();
	$("#shade").hide();
}
function addedit(){
	var maxeditid = parseInt($("#maxeditid").val());
	if(maxeditid=='' || maxeditid==null){
		alert('错误的参数ID');
		return false;
	}else if(maxeditid>7){
		alert('最多只能加载8条图文信息');
		return false;
	}
	var id=maxeditid+1;
	$(".editcontent").hide();
	$(".normal").removeClass("select");
	$(".first").removeClass("select");
	$(".editmode").hide();
	var str='<div class="editid_'+id+' editcontent" data-id="'+id+'">';
	str+='<ul class="baseedit"><li><input type="text" name="title'+id+'" id="title'+id+'" class="title" onBlur="settit(this)" placeholder="请在这里输入标题" /></li>';
	str+='<li><input type="text" name="author'+id+'" id="author'+id+'" class="author" placeholder="请输入作者" /></li>';
	str+='<li><textarea name="content'+id+'" id="content'+id+'" class="content" style="visibility:hidden;"></textarea></li>';
	str+='<li>图文链接：<input type="text" name="linkurl'+id+'" class="linkurl'+id+' wxtextput" /> <input type="button" class="wxbutton" onclick="showabove('+id+')" value="从功能库选择" /></li></ul>';
	str+='<ul class="moreedit"><li>发布样式编辑</li><li>封面 <span>小图片建议尺寸：200像素 * 200像素</span></li>';
	str+='<li><input type="file" class="fhidden" name="img'+id+'" id="img'+id+'" onChange="uploadpic('+id+')" /><input type="button" class="wxbutton_normal" value="本地上传" /> <input type="button" class="wxbutton_normal" onClick="getmedialist('+id+')" value="选择素材" /></li>';
	str+='<li>摘要 <span>选填，如果不填写会默认抓取正文前54个字</span></li><li><textarea name="desc'+id+'" id="desc'+id+'" class="desc"></textarea></li></ul>';
	str+='</div>';
	var navstr='<dl class="normal navid_'+id+' select" data-id="'+id+'"><div onClick="selnav(this)"><dd class="tit navtit" >标题</dd><dd class="img" ><img src="<{$ipath}>wx/images/normalimg.png" width="100%"><span class="pichiddvalue"></span></dd></div><dd class="editmode" onclick="delnav('+id+')" style="display:block"><i class="icon_del"></i></dd></dl>';
	$(".navaddcontent").append(navstr);
	$("#edit").append(str);
	$(".editid_"+id).show();
	$("#maxeditid").val(id);
	$("#maxeditid").attr("data-id",id);
	K.create("#content"+id,{cssPath:"lib/kdeditor/plugins/code/prettify.css",uploadJson:"lib/kdeditor/php/upload_json.php",fileManagerJson:"lib/kdeditor/php/file_manager_json.php",allowFileManager:true,})
}
function selnav(obj){
	$(".normal").removeClass("select");
	$(".first").removeClass("select");
	$(".editmode").hide();
	var id=$(obj).parent().attr("data-id");
	$(".editcontent").hide();
	$(".editid_"+id).show();
	$(obj).parent().addClass("select");
	if(id>1){
		$(obj).parent().children(".editmode").show();
		$(".editid_"+id).find(".ke-container").width("100%");
	}
}
function showediturl(obj){
	if($(obj).is(":checked")){
		$(obj).next("span").show();
	}else{
		$(obj).next("span").hide();
	}
}
function delnav(n){
	if(confirm('删除后内容不能恢复，确认删除吗?')){
		$(".navid_"+n).remove();
		$(".editid_"+n).remove();
		var m = parseInt(n) - 1;
		$(".editid_"+m).show();
		$(".navid_"+m).addClass("select");
		if(m>1){
			$(".navid_"+m).children(".editmode").show();
		}
		return true;
	}else{
		return false;
	}
}
function showabove(id){
    $('.c16').html('');
    $('.c5').html('');
    $('.c6').html('');
    $('.c7').html('');
    $('.c9').html('');
	$("#shade").show();
	$("#above").show();
	$.ajax({
	type: "POST",
	url: "?g=user&m=functiondata&a=index",
	dataType: "json",
	success: function (data) {
		if (data.status == 1) {
			for (ritem in data.msg) {
				var name = data.msg[ritem].name;
				var url = "http://vq.zhongsou.com/index.php?g=User&m="+data.msg[ritem].m + "&a=" + data.msg[ritem].a + "&" + data.msg[ritem].o +"token="+data.token ;
				if (data.msg[ritem].classid == '16') {
					var spanstr = "<li class='class_16' data-url="+  url +"' onclick='getmyurl(this,"+id+")'>" + name +  "</li><li class='class_16 mywebsite' onclick='showweb(this)'>我的网站</li>";
					$('.c16').append(spanstr);
				} else if (data.msg[ritem].classid == '5') {
					var spanstr = "<li class='class_5' data-url="+  url +"' onclick='getmyurl(this,"+id+")'>" + name + "</li>";
					$('.c5').append(spanstr);
				} else if (data.msg[ritem].classid == '6') {
					var spanstr = "<li class='class_6' data-url="+  url +"' onclick='getmyurl(this,"+id+")'>" + name + "</li>";
					$('.c6').append(spanstr);
				} else if (data.msg[ritem].classid == '7') {
					var spanstr = "<li class='class_7' data-url="+  url +"' onclick='getmyurl(this,"+id+")'>" + name + "</li>";
					$('.c7').append(spanstr);
				} else if (data.msg[ritem].classid == '10') {
					var spanstr = "<li class='class_9' data-url="+  url +"' onclick='getmyurl(this,"+id+")'>" + name + "</li>";
					$('.c9').append(spanstr);
				}
			}
//			if ($('.c16>li').length>0) {
//				$('.c16').html(spanstr+'<li class="class_16 mywebsite" onclick="showweb(this,'+id+')">我的网站</li>');
//			}
		} else {
			alert('error');
			return false;
		}
	}
})
}

function getmyurl(obj,id){
    var str=$(obj).attr("data-url");
    var bnum = str.indexOf("m=");
    var endnum = str.indexOf('&a');
    var url_m = str.substr((bnum+2),(endnum-bnum-2));
    $.ajax({
        type: "POST",
        url: "?g=user&m=functiondata&a="+url_m ,
        dataType: "json",

        success:function(data){
            if(data.status ==1){
                var teststr = '';
                for(datainfo in data.item){
                     teststr += "<li><p>"+data.item[datainfo].name+"<input type='text' style='width:400px' value= "+data.item[datainfo].linkcode+"></p><div><span onclick='inserturl(this,"+id+")'>插入</span><span><a href='"+data.item[datainfo].linkcode+"' target='_blank'>查看</a></span></div></li>"
                }
                $('.addd').html(teststr);
            }else{
                alert("暂时没有选择项，请先创建您的应用~！");
                return false;
            }
        }
    })
}
function inserturl(o,id){
	var link = $(o).next().children('a').attr('href');
	$(".linkurl"+id).val(link);
	$(".sec-sort").html('');
	$(".addd").html('');
	$('#above').hide();
	$('#shade').hide();

}
function showweb(obj,id){
	var html='';
	html += "<li><p>微信<input type='text' style='width:400px' value='<{$vqhost}>index.php?g=Wap&m=Index&a=index&pla=4&token=<{$usertoken}>'></p><div><span onclick='inserturl(this,"+id+")'>插入</span><span><a href='<{$vqhost}>index.php?g=Wap&m=Index&a=index&pla=4&token=<{$usertoken}>' target='_blank'>查看</a></span></div></li>";
	html += "<li><p>APP<input type='text' style='width:400px' value='<{$vqhost}>index.php?g=Wap&m=Index&a=index&pla=9&token=<{$usertoken}>'></p><div><span onclick='inserturl(this,"+id+")'>插入</span><span><a href='<{$vqhost}>index.php?g=Wap&m=Index&a=index&pla=9&token=<{$usertoken}>' target='_blank'>查看</a></span></div></li>";
	html += "<li><p>WAP<input type='text' style='width:400px' value='<{$vqhost}>index.php?g=Wap&m=Index&a=index&pla=13&token=<{$usertoken}>'></p><div><span onclick='inserturl(this,"+id+")'>插入</span><span><a href='<{$vqhost}>index.php?g=Wap&m=Index&a=index&pla=13&token=<{$usertoken}>' target='_blank'>查看</a></span></div></li>";
	$('.addd').html(html);
	$(obj).addClass('secCur').siblings().removeClass('secCur');
}

    </script>
<iframe width="0" height="0" scrolling="no" frameborder="0" name="hiddfrm" id="hiddfrm" style="display:none"></iframe>
</body>
</html>
